package edu.pucsp.predatorprey.tela.util;

import java.awt.GridBagConstraints;
import java.awt.Insets;

/**
 * 
 * @author Bruno.ortiz
 * 
 */
public class GridBagConstraintsBuilder {

	private static final int DEFAULT_INSETS_VALUE = 5;

	private int gridx = 0;

	private int gridy = 0;

	private int fill = java.awt.GridBagConstraints.BOTH;

	private int ipadx = 1;

	private double weightx = 0.0;

	private double weighty = 0.0;

	private int gridwidth = 1;

	private int gridheight = 1;

	private int anchor = GridBagConstraints.CENTER;

	private Insets insets = new Insets(DEFAULT_INSETS_VALUE, DEFAULT_INSETS_VALUE, DEFAULT_INSETS_VALUE, DEFAULT_INSETS_VALUE);

	private GridBagConstraintsBuilder() {
	}

	public static GridBagConstraintsBuilder createContraint() {
		return new GridBagConstraintsBuilder();
	}

	/**
	 * @return the built gridbagconstraint
	 */
	public GridBagConstraints build() {
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = this.gridx;
		gridBagConstraints.gridy = this.gridy;
		gridBagConstraints.fill = this.fill;
		gridBagConstraints.ipadx = this.ipadx;
		gridBagConstraints.weightx = this.weightx;
		gridBagConstraints.weighty = this.weighty;
		gridBagConstraints.insets = this.insets;
		gridBagConstraints.gridwidth = this.gridwidth;
		gridBagConstraints.gridheight = this.gridheight;
		gridBagConstraints.anchor = this.anchor;
		return gridBagConstraints;
	}

	/**
	 * Sets the grid value of a GridBagConstraint
	 * 
	 * @param x
	 *            value of the grid
	 * @param y
	 *            value of the grid
	 * @return the GridBagContraintBuilder
	 */
	public GridBagConstraintsBuilder grid(int x, int y) {
		this.gridx = x;
		this.gridy = y;
		return this;
	}

	/**
	 * Sets the x grid value of a GridBagConstraint
	 * 
	 * @param x
	 *            value of the grid
	 * @return the GridBagContraintBuilder
	 */
	public GridBagConstraintsBuilder gridx(int x) {
		this.gridx = x;
		return this;
	}

	/**
	 * Sets the y grid value of a GridBagConstraint
	 * 
	 * @param y
	 *            value of the grid
	 * @return the GridBagContraintBuilder
	 */
	public GridBagConstraintsBuilder gridy(int y) {
		this.gridy = y;
		return this;
	}

	/**
	 * Sets the fill parameter of the GridBagConstraint
	 * 
	 * @param value
	 *            to be set
	 * @return the GridBagContraintBuilder
	 */
	public GridBagConstraintsBuilder fill(int value) {
		this.fill = value;
		return this;
	}

	/**
	 * Sets the x pad value of a GridBagConstraint
	 * 
	 * @param value
	 *            to be set
	 * @return the GridBagContraintBuilder
	 */
	public GridBagConstraintsBuilder ipadx(int value) {
		this.ipadx = value;
		return this;
	}

	/**
	 * Sets the x weight value of a GridBagConstraint
	 * 
	 * @param value
	 *            to be set
	 * @return the GridBagContraintBuilder
	 */
	public GridBagConstraintsBuilder weightx(double value) {
		this.weightx = value;
		return this;
	}

	/**
	 * Sets the y weight value of a GridBagConstraint
	 * 
	 * @param value
	 *            to be set
	 * @return the GridBagContraintBuilder
	 */
	public GridBagConstraintsBuilder weighty(double value) {
		this.weighty = value;
		return this;
	}

	/**
	 * Sets the grid widht of a GridBagConstraint
	 * 
	 * @param value
	 *            to be set
	 * @return the GridBagContraintBuilder
	 */
	public GridBagConstraintsBuilder gridwidth(int value) {
		this.gridwidth = value;
		return this;
	}

	/**
	 * Sets the grid widht of a GridBagConstraint
	 * 
	 * @param value
	 *            to be set
	 * @return the GridBagContraintBuilder
	 */
	public GridBagConstraintsBuilder gridheight(int value) {
		this.gridheight = value;
		return this;
	}

	/**
	 * Sets the anchor value of a GridBagConstraint
	 * 
	 * @param value
	 *            to be set
	 * @return the GridBagContraintBuilder
	 */
	public GridBagConstraintsBuilder anchor(int value) {
		this.anchor = value;
		return this;
	}

	/**
	 * Sets the insets of a GridBagConstraint
	 * 
	 * @param top
	 *            to be set
	 * @param left
	 *            to be set
	 * @param bottom
	 *            to be set
	 * @param right
	 *            to be set
	 * @return the GridBagContraintBuilder
	 */
	public GridBagConstraintsBuilder insets(int top, int left, int bottom, int right) {
		this.insets = new Insets(top, left, bottom, right);
		return this;
	}
}
